{extend name="layout" /}
{block name="title"}标签管理{/block}
{block name="style"} <style>
    .layui-btn-small {
        padding: 0 15px;
    }

    .layui-form-checkbox {
        margin: 0;
    }

    tr td:not(:nth-child(0)),
    tr th:not(:nth-child(0)) {
        text-align: center;
    }

    #dataConsole {
        text-align: center;
    }
    /*分页页容量样式*/
    /*可选*/
    .layui-laypage {
        display: block;
    }

    /*可选*/
    .layui-laypage > * {
        float: left;
    }
    /*可选*/
    .layui-laypage .laypage-extend-pagesize {
        float: right;
    }
    /*可选*/
    .layui-laypage:after {
        content: ".";
        display: block;
        height: 0;
        clear: both;
        visibility: hidden;
    }

    /*必须*/
    .layui-laypage .laypage-extend-pagesize {
        height: 30px;
        line-height: 30px;
        margin: 0px;
        border: none;
        font-weight: 400;
    }
    /*分页页容量样式END*/
</style>{/block}
{block name="body"}
<div style="margin-bottom:5px;">
    <span class="layui-breadcrumb" >
  <a href="{:url('/admin/label')}">首页</a>
  <a><cite>添加标签</cite></a>
</span>
</div>
<blockquote class="layui-elem-quote layui-text">
    添加标签
</blockquote>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">标签名</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="label" autocomplete="off" placeholder="请输入标题" class="layui-input" value="{$data.name}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属分类</label>
        <div class="layui-input-block">
            <select name="type" lay-filter="aihao">
                {volist name="labelType" id="type"}
                <option value="{$key}" {eq name="$data.type" value="$key" } selected {/eq}>{$type}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <button class="layui-btn" style="width:230px;" lay-submit="" lay-filter="edit">编辑</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<!-- layui规范化用法 -->
<script type="text/javascript">
    layui.define(['form','element'],function(){
        var form = layui.form();
        //自定义验证
        form.verify({
            label: [/^[\S]{3,12}$/, '标签名必须6到12位'],
        });
        $('body').keydown(function (e) {
            if (e.keyCode == 13) {  //Enter键
                $('button[lay-filter=login]').click();
            }
        });
        form.on('submit(edit)', function (data) {
            var index = layer.load(1);
            var url = baseUrl+"api/label/{$id}";
            var data = $('form').serialize();
            urlAjax(url,data,function(data){
                    layer.close(index);
                    if(data.status){
                        layer.msg(data.info, { icon: 5 });
                    }else{
                        layer.msg(data.info, { icon: 6 });
                        layer.closeAll('page');
                        setTimeout(function(){
                            location.href = data.url;
                        },1500);
                    }
                },
                function(){
                    layer.close(index);
                    layer.msg('网络错误，请重试', { icon: 5 });
                },'PUT');
            return false;
        });
    });
</script>

{/block}